#include <cstdio>
#include <queue>

using namespace std;

struct Node
{
    int i, j;
    Node( int _i, int _j )
        : i( _i ), j( _j ) { }
    Node( ) { }
};

const int c[ 9 ] = {  3, 4, 6, 4, 4, 6, 4, 3 };
const int li[ 9 ][ 8 ] = { { 1, 2, 3 }, { 0, 2, 4, 5 }, { 0, 1, 3, 4, 5, 6 },
               { 0, 2, 5, 6 }, { 1, 2, 5, 7 }, { 1, 2, 3, 4, 6, 7 }, { 2, 3, 5, 7 }, { 4, 5, 6 } };

int s[ 9 ], r[ 9 ], counts;
bool visit[ 10 ], ok[ 8 ][ 10 ];

void init( )
{
    int i, j;
    counts = 0;
    for ( i = 1; i <= 8; i++ )
        visit[ i ] = false;
    for ( i = 0; i < 8; i++ )
        for ( j = 1; j <= 8; j++ )
            ok[ i ][ j ] = true;
    for ( i = 0; i < 8; i++ )
    {
        scanf("%d", &s[ i ]);
        if ( s[ i ] != 0 )
        {
            visit[ s[ i ] ] = true;
            for ( j = 0; j < c[ i ]; j++ )
                ok[ li[ i ][ j ] ][ s[ i ] - 1 ] = ok[ li[ i ][ j ] ][ s[ i ] + 1 ] = false;
        }
    }
}

void dfs( int p )
{
    if ( p == 8 )
    {
        int i;
        for ( i = 0; i < 8; i++ )
            r[ i ] = s[ i ];
        counts++;
    }
    if ( p < 8 )
    {
        if ( s[ p ] != 0 )
        {
            dfs( p + 1 );
            return ;
        }
        int i, j;
        queue<Node> q;
        while ( !q.empty( ) )
            q.pop( );
        Node t;
        for ( i = 1; i <= 8; i++ )
        {
            if ( ok[ p ][ i ] && visit[ i ] == false )
            {
                visit[ i ] = true;
                for ( j = 0; j < c[ p ]; j++ )
                {
                    if ( ok[ li[ p ][ j ] ][ i - 1 ] ) 
                    {
                        q.push( Node( li[ p ][ j ], i - 1 ) );
                        ok[ li[ p ][ j ] ][ i - 1 ] = false;
                    }
                    if ( ok[ li[ p ][ j ] ][ i + 1 ] )
                    {
                        q.push( Node( li[ p ][ j ], i + 1 ) );
                        ok[ li[ p ][ j ] ][ i + 1 ] = false;
                    }
                }
                s[ p ] = i;
                dfs( p + 1 );
                visit[ i ] = false;
                while ( !q.empty( ) )
                {
                    t = q.front( );
                    q.pop( );
                    ok[ t.i ][ t.j ] = true;
                }
                s[ p ] = 0;
            }
        }
    }
}

void print( int p )
{
    printf("Case %d:", p);
    if ( counts == 0 )
        printf(" No answer\n");
    if ( counts == 1 )
    {
        int i;
        for ( i = 0; i < 8; i++ )
            printf(" %d", r[ i ]);
        printf("\n");
    }
    if ( counts > 1 )
        printf(" Not unique\n");
}

int main( )
{
    int t, i;
    scanf("%d", &t);
    for ( i = 1; i <= t; i++ )
    {
        init( );
        dfs( 0 );
        print( i );
    }
    return 0;
}
